//
//  PhotoCollectionView.m
//  卢卡的时光网
//
//  Created by 卡神 on 15/7/23.
//  Copyright © 2015年 lok. All rights reserved.
//

#import "PhotoCollectionView.h"
#import "PhotoCollectionViewCell.h"
#import "common.h"

@implementation PhotoCollectionView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (nonnull instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(nonnull UICollectionViewLayout *)layout {
    if (self = [super initWithFrame:frame collectionViewLayout:layout]) {
        self.delegate = self;
        self.dataSource = self;
        [self registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"photoCell"];
    }
    return self;
}

- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [_imageUrl count];
}

- (void)setCurrentImage:(NSInteger)currentImage {
    _currentImage = currentImage;
    self.contentOffset = CGPointMake(kWidth * currentImage, 0);
}

- (void)setImageUrl:(NSMutableArray *)imageUrl {
    _imageUrl = imageUrl;
    [self reloadData];
}

- (UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    PhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"photoCell" forIndexPath:indexPath];
    cell.imageUrl = _imageUrl[indexPath.row];
    return cell;
}



@end
